package com.qcby.controller;

import com.qcby.entity.*;
import com.qcby.service.CheckingsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/checkings")
public class CheckingsController {

    @Autowired
    private CheckingsService checkingsService;

    @PostMapping("/getUserIdByName")
    @ResponseBody
    public Result<Integer> getUserIdByName(String userName){
        return checkingsService.getUserIdByName(userName);
    }

    @PostMapping("/findUserInfoByUserId")
    @ResponseBody
    public Result<User> findUserInfoByUserId(int userId){
        return checkingsService.findUserInfoByUserId(userId);
    }

    @PostMapping("/getCheckinsByUserId")
    @ResponseBody
    public Result<List<UserCheckin>> getCheckinsByUserId(@Param("Uid") Integer Uid, @Param("shopId") Integer shopId){
//        System.out.println(checkingsService.getCheckinsByUserId(Uid));
        return checkingsService.getCheckinsByUserId(Uid,shopId);
    }

    @PostMapping("/getCommentsByCheckinId")
    @ResponseBody
    public Result<List<Review>> getCommentsByCheckinId(Integer checkinId){
//        System.out.println(checkingsService.getCommentsByCheckinId(checkinId));
        return checkingsService.getCommentsByCheckinId(checkinId);
    }

    @PostMapping("/getChildrenCommentsByParentId")
    @ResponseBody
    public Result<List<Review>> getChildrenCommentsByParentId(Integer parentId){
//        System.out.println(checkingsService.getChildrenCommentsByParentId(parentId));
        return checkingsService.getChildrenCommentsByParentId(parentId);
    }

    @PostMapping("/addComment")
    @ResponseBody
    public Result<Integer> addComment(Integer checkinId, Integer userId, String content){
//        System.out.println("checkinId = " + checkinId);
//        System.out.println("userId = " + userId);
//        System.out.println("content = " + content);
        return checkingsService.addComment(checkinId, userId,content);
    }

    @PostMapping("/replyComment")
    @ResponseBody
    public Result<Integer> replyComment(Integer checkinId, Integer userId, String content, Integer parentId){
        return checkingsService.replyComment(checkinId, userId, content, parentId);
    }

    @PostMapping("/likeCheckin")
    @ResponseBody
    public Result<Integer> likeCheckin(Integer checkinId, Integer userId){
        return checkingsService.likeCheckin(checkinId, userId);
    }

    @PostMapping("cancelCheckinLike")
    @ResponseBody
    public Result<Integer> cancelCheckinLike(Integer checkinId, Integer userId){
        return checkingsService.cancelCheckinLike(checkinId, userId);
    }

    @PostMapping("/likeComment")
    @ResponseBody
    public Result<Integer> likeComment(Integer commentId, Integer userId){
        return checkingsService.likeComment(commentId, userId);
    }

    @PostMapping("/cancelCommentLike")
    @ResponseBody
    public Result<Integer> cancelCommentLike(Integer commentId, Integer userId){
        return checkingsService.cancelCommentLike(commentId, userId);
    }

    @PostMapping("/getUserLikedCheckins")
    @ResponseBody
    public Result<List<Integer>> getUserLikedCheckins(Integer userId){
        return checkingsService.getUserLikedCheckins(userId);
    }

    @PostMapping("/getUserLikedComments")
    @ResponseBody
    public Result<List<Integer>>getUserLikedComments(Integer userId, Integer checkinId){
        return checkingsService.getUserLikedComments(userId, checkinId);
    }

    @ResponseBody
    @PostMapping("/addCheckin")
    public Result<Integer> addCheckin(@RequestBody Checkings checkings){
        return checkingsService.addCheckin(checkings);
    }

    @PostMapping("/updateShareStatus")
    @ResponseBody
    public Result<Integer> updateShareStatus(int checkinId, int isShared, int userId){
        return checkingsService.updateShareStatus(checkinId, isShared, userId);
    }
}
